<?php

namespace app\common\service\worker;

use think\worker\Server;

class DpWorker extends Server
{
    protected $socket = 'websocket://0.0.0.0:2346';

    public function onMessage($connection,$data): void
    {
        $connection->send('hello world'.json_encode($data));
    }
    
    public function onConnect($connection): void
    {
        $connection->send('连接成功');
    }

    public function onClose($connection): void
    {
        
    }

    public function onWorkerStart($worker): void
    {
        
    }

    public function onError($connection,$code,$msg): void
    {
        echo "error $code $msg\n";
    }
}